package com.video.user.controller;


import com.video.api.dto.InsertVideoDto;
import com.video.common.enumeration.AppHttpCodeEnum;
import com.video.common.result.PageResult;
import com.video.common.result.ResponseResult;
import com.video.user.domain.dto.UpdateVideoCountDto;
import com.video.user.domain.dto.QueryPageDto;
import com.video.user.domain.entity.VideoList;
import com.video.user.service.IVideoListService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author la
 * @since 2024-11-09
 */
@RestController
@RequestMapping("/video-list")
@RequiredArgsConstructor
public class VideoListController {

    private final IVideoListService videoListService;

    /*
     * 新增或编辑视频
     * */
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody InsertVideoDto dto) {
        videoListService.InsertList(dto);
        return ResponseResult.okResult("操作成功");
    }

    /*
     * 分页查询视频列表
     * */
    @GetMapping("/page")
    public ResponseResult queryList(QueryPageDto dto) {
        PageResult result = videoListService.queryVideoList(dto);
        return ResponseResult.okResult(result);
    }
    /**
     * 删除视频
     */
    @DeleteMapping("/delete/{id}")
    public ResponseResult delete(@PathVariable("id") Long id) {
        videoListService.removeVideoById(id);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    /*
     * 新增视频点赞数量
     * */
    @GetMapping("/updateVideoCount")
    public ResponseResult updateVideoCount(UpdateVideoCountDto dto) {

        videoListService.updateVideoCount(dto);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    /**
     * 查看视频信息
     */
    @GetMapping("/info/{id}")
    public ResponseResult info(@PathVariable("id") Long id) {
        VideoList videoList = videoListService.getById(id);
        return ResponseResult.okResult(videoList);
    }
}
